Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add skipSuperCoding Codable Options #5

Merged
merged 3 commits into from
Jan 13, 2025
Merged

Conversation

WendellXY
Copy link
Owner

This pull request introduces significant enhancements to the @Codable macro by adding a new feature called CodableOptions, which allows for customizable behavior when encoding and decoding types.

  • CodableOptions Implementation: A new CodableOptions structure has been introduced to enable users to customize the behavior of the @Codable macro. This includes the ability to skip superclass encode/decode calls when the superclass does not conform to Codable. This change enhances flexibility in code generation and allows for more tailored implementations of Codable types.

  • Inheritance Logic Update: The logic within the CodableMacro has been updated to ensure that superclass coding is not skipped unless the skipSuperCoding option is explicitly set. This ensures that all relevant properties from superclasses are encoded correctly, improving the handling of inheritance in Codable types.

  • Comprehensive Testing: New tests have been added to validate the functionality of the @Encodable, @Decodable, and @Codable macros with the .skipSuperCoding option. These tests ensure that the macros expand correctly to the expected Swift code and that the generated classes handle encoding and decoding appropriately, even when not inheriting properties from superclasses. This enhances the overall test coverage for the Codable macros.

These changes aim to improve the usability and reliability of the Codable macros, making them more adaptable to various coding scenarios.

Introduce `CodableOptions` to allow customization of the `@Codable` macro. 
Update the macro to accept options, enabling users to skip super 
encode/decode calls when the superclass does not conform to 
`Codable`. Refactor related methods to utilize the new options, 
enhancing flexibility in code generation.
Update the inheritance clause logic in CodableMacro to ensure that 
superclass coding is not skipped when the `skipSuperCoding` option 
is not present. This change enhances the handling of inheritance 
for Codable types, ensuring that all relevant properties are 
encoded correctly.
Add tests for the `@Encodable`, `@Decodable`, and `@Codable` macros 
with the `.skipSuperCoding` option. These tests verify that the 
macros correctly expand to the expected Swift code, ensuring that 
the generated classes handle encoding and decoding without 
inheriting properties from superclasses. This enhances the test 
coverage for the Codable macros and ensures their correct 
functionality in various scenarios.
@WendellXY WendellXY merged commit 3d5b379 into main Jan 13, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant